unit ShellDDE;

interface

uses
  Classes;

const
  ssNormal            = 1;
  ssIcon              = 2;
  ssMaximize          = 3;
  ssRestoreNoActivate = 4;
  ssRestore           = 5;
  ssMinimize          = 6;
  ssIconNoActivate    = 7;
  ssNoActivate        = 8;

function  ShellName: string;
procedure ShellCreateGroup( GroupName: string; CommonGroup: boolean= false );
procedure ShellDeleteGroup( GroupName: string; CommonGroup: boolean= false );
procedure ShellShowGroup( GroupName: string; ShowCmd: integer; CommonGroup: boolean= false );
procedure ShellAddItem( CmdLine, Name: string );
procedure ShellDeleteItem( Name: string );
procedure ShellReplaceItem( Name: string );

function  ShellGetGroups: TStrings;

implementation

uses
  DDEMan, SysUtils, IniFiles;

function ShellName: string;
var
  ini : TIniFile;
begin
  ini := TIniFile.Create('system.ini');
  result := ini.ReadString('boot','shell','PROGMAN.EXE');
  result := UpperCase(copy(result,1,pos('.',result)-1));
  ini.Free;
end;

function ExecMacro( macro: string ): boolean;
var
  d : TDDEClientConv;
  b : array [0..255] of char;
  n : string[8];
begin
  n := ShellName;
  if n='EXPLORER' then n := '';
  d := TDDEClientConv.Create(nil);
  d.SetLink(n,'PROGMAN');
  result := d.ExecuteMacro(StrPCopy(b,macro),true);
  d.Free;
end;

function CommonGroupToInt( CommonGroup: boolean ): integer;
begin
  if CommonGroup then result := 1 else result := 0;
end;

procedure ShellCreateGroup( GroupName: string; CommonGroup: boolean );
begin
  ExecMacro(format('[CreateGroup("%s",%d)]',[GroupName,CommonGroupToInt(CommonGroup)]));
end;

procedure ShellDeleteGroup( GroupName: string; CommonGroup: boolean );
begin
  ExecMacro(format('[DeleteGroup("%s",%d)]',[GroupName,CommonGroupToInt(CommonGroup)]));
end;

procedure ShellShowGroup( GroupName: string; ShowCmd: integer; CommonGroup: boolean  );
begin
  ExecMacro(format('[ShowGroup("%s",%d,%d)]',[GroupName,ShowCmd,CommonGroupToInt(CommonGroup)]));
end;

procedure ShellAddItem( CmdLine, Name: string );
begin
  ExecMacro(format('[AddItem("%s","%s")]',[CmdLine,Name]));
end;

procedure ShellDeleteItem( Name: string );
begin
  ExecMacro(format('[DeleteItem("%s")]',[Name]));
end;

procedure ShellReplaceItem( Name: string );
begin
  ExecMacro(format('[ReplaceItem("%s")]',[Name]));
end;

function  ShellGetGroups: TStrings;
var
  d : TDDEClientConv;
  s : PChar;
  n : string[8];
begin
  d := TDDEClientConv.Create(nil);
  n := ShellName;
  if n='EXPLORER' then n := '';
  d.SetLink(n,'PROGMAN');
  result := TStringList.Create;
  s := d.RequestData('GROUPS');
  if s<>nil then result.SetText(s);
  StrDispose(s);
  d.Free;
end;

end.
